<template>
	<view>
		<view class="daogou">
			<view class="banner">
				<swiper circular indicator-dots autoplay>
							<swiper-item v-for="(e,i) in extList.topBannerList" :key="i">
								<image :src="e.banner"></image>
							</swiper-item>
						</swiper>
			</view>
			<view class="tarbar">
				<view class="tarbar-item" v-for="(t,i) in extList.buttonList" @click="goList(t.specialId,t.banner)" :key="i">
					<view class="tar-in" ><img :src="t.img" alt=""></view>
					<text class="tar-title">{{t.specialName}}</text>
				</view>
			</view>
			<text class='title'>-每日上新 好劵不断-</text>
			<view class="pay">
				<view class="pay-item" v-for="(p,i) in payList" 
				:class="{'pay-left':i %2 ==0 || i==0}" :key="i"
				@click="godetile(p.itemId)"
				>
					<img class="good-img" :src="p.img" alt="">
					<view class="pay-top">

						<text class="pay-name"><text class="pay-type">{{p.itemMarketType}}</text>{{p.goodsName}}</text>
					</view>
					<view class="pay-middle">
						<view>
							<text class="newprice">￥{{Math.round((p.salePrice-p.couponValue)*10)/10}}</text>
							<text class="saleprice">￥{{p.salePrice}}</text>
						</view>
						<text class="pay-count">已售{{p.saleQty}}</text>
					</view>
					<view class="pay-bottom">
						<view class="convalue">{{p.couponValue}}元劵
							<view class="left">
								
							</view>
							<view class="right">
							
							</view>
						</view>

						<text class="shop-name">{{p.shopName}}</text>
					</view>
				</view>
			</view>

		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				time: 0,
				payList: [],
				
				extList:[]
			}
		},
		methods: {
			getData() {
				uni.request({
					url: `https://appfly.cn/api/daogouCommon/init`,
					header: {
						cookie: 'easyweb=2001; target=blank; navbar=0; count=20; verCode=1211; appPackage=cn.appfly.cookbook; lang=zh-CN; token=; __gads=ID; __gpi=UID'
					},
					success: (res) => {
						this.payList = res.data.data
						this.extList=res.data.extra
						uni.stopPullDownRefresh();
						// console.log(this.payList);
					}
				});
			},
			goList(id,img){
				uni.navigateTo({
					url: `/pages/goodList/goodList?id=${id}&img=${img}`
				})
			},
			godetile(id){
	
					uni.navigateTo({
						url: `/pages/paydetile/paydetile?id=${id}`
					})
				
			}

		},
		mounted() {
			this.getData()
		},
		onLoad() {
			uni.startPullDownRefresh();
		},
		onPullDownRefresh() {
			this.getData()
		}
	}
</script>

<style lang="scss">
	.daogou {
		padding: 10px 0;

		// width: 93vw;
		.title {
			display: block;
			color: red;
			width: 100vw;
			text-align: center;
			padding: 20px 0;
		}
		
		.banner{
			width: 93vw;
			padding: 10px 12px;
			height: 150px;
			image{
				height: 100%;
				width: 100%;
			}
		}

		.tarbar {
			display: flex;
			flex-wrap: wrap;
			font-size: 12px;

			// background-color: rgb(121,121, 121)
			.tarbar-item {
				flex: 0 0 16%;
				padding: 2%;
				display: flex;
				flex-direction: column;

				.tar-in {
					color: white;
					width: 100%;
					height: 50px;
					border-radius: 20px;
					text-align: center;
					line-height: 50px;
					font-size: 18px;
					img{
						width: 100%;
						height: 100%;
					}
				}

				.tar-title {
					text-align: center
				}
			}
		}

		.pay {
			display: flex;
			flex-wrap: wrap;
			padding: 10px 12px;
			font-size: 14px;

			.pay-item {
				flex: 0 0 48%;
				margin-bottom: 20px;

				&.pay-left {
					margin-right: 4%;
				}

				.good-img {
					width: 100%;
					height: 170px;
				}

				.pay-top {
					width: 100%;
					height: 30px;

					.pay-type {
						background-color: red;
						color: white;
						font-size: 12px;
						display: inline-block;
						width: 30px;
						text-align: center;
						border-radius: 4px;
						margin-right: 5px;
					}

					.pay-name {
						display: inline-block;
						height: 30px;
						width: 130px;
						text-overflow: ellipsis;
						white-space: nowrap;
						overflow: hidden;
					}
				}

				.pay-middle {
					display: flex;
					justify-content: space-between;
					font-size: 10px;
					color: #999;

					.newprice {
						color: red;
						font-size: 18px
					}

					.saleprice {
						text-decoration: line-through;
					}

					.pay-count {
						line-height: 30px;
					}
				}

				.pay-bottom {
					display: flex;
					flex-direction: column;
					color: #999;
					

					.convalue {
						background-color: red;
						width: 75px;
						height: 20px;
						line-height: 20px;
						font-size: 13px;
						border-radius: 6px;
						text-align: center;
						color: white;
						position: relative;
						margin-bottom: 10px;

						.left {
							position: absolute;
							left: -5px;
							top: 50%;
							transform: translateY(-50%);
							background-color: #fff;
							width: 10px;
							height: 10px;
							border-radius: 999px;
						}
						.right{
							position: absolute;
							right: -5px;
							top: 50%;
							background-color: #fff;
							transform: translateY(-50%);
							width: 10px;
							height: 10px;
							border-radius: 999px;
						}
					}

					
				}
			}
		}
	}
</style>
